package com.glxy.service.impl;

import com.glxy.dao.impl.UserDaoImpl;
import com.glxy.pojo.User;
import com.glxy.service.LoginService;
import com.glxy.utils.EncryptionUtil;

import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

public class LoginServiceImpl implements LoginService {

    private final UserDaoImpl userDao = new UserDaoImpl();

    @Override
    public Long MatchUser(String userCode, String pwd) {

        User user = userDao.findByCode(userCode);

        if (user != null){

            if (user.getUserPassword().equals(pwd)){
                return user.getId();
            }else{
                return (long) -1;
            }

//            try {
//                String EncryPwd = EncryptionUtil.Encryption(pwd);
//            } catch (NoSuchAlgorithmException e) {
//                e.printStackTrace();
//            }

        }else {
            return (long)-2;
        }
    }

    public void newPassword(User user){
        userDao.update(user);
    }
}
